// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

    lb:{
      up:[{
        name: "美食",
        src: "/pages/images/1.png"
      }, {
        name: "甜点饮品",
        src: "/pages/images/2.png"
      }, {
        name: "美团超市",
        src: "/pages/images/3.png"
      }, {
        name: "正餐精选",
        src: "/pages/images/4.png"
      }, {
        name: "生鲜果蔬",
        src: "/pages/images/5.png"
      }, {
        name: "全部商家",
        src: "/pages/images/6.png"
      }, {
        name: "免配送费",
        src: "/pages/images/7.png"
      }, {
        name: "新商家",
        src: "/pages/images/8.png"
      }],
      dwon: [{
        name: "美食",
        src: "/pages/images/1.png"
      }, {
        name: "甜点饮品",
        src: "/pages/images/2.png"
      }, {
        name: "美团超市",
        src: "/pages/images/3.png"
      }, {
        name: "正餐精选",
        src: "/pages/images/4.png"
      }, {
        name: "生鲜果蔬",
        src: "/pages/images/5.png"
      }, {
        name: "全部商家",
        src: "/pages/images/6.png"
      }, {
        name: "免配送费",
        src: "/pages/images/7.png"
      }, {
        name: "新商家",
        src: "/pages/images/8.png"
      }]
    },

    list:[],
    page:1,
    pageSize:10
  },

  getList(){
    wx.request({
      url: 'http://127.0.0.1:3000/data',
      method:'GET',
      data:{
        page:this.data.page,
        pageSize:this.data.pageSize
      },
      success:res=>{
        console.log(res);
        this.setData({
            list:[...this.data.list,...res.data]
        })
      },
      fail:()=>{

      }
    })
  },  


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getList()
  },

  //
  onReachBottom() {
    console.log(1);
    this.setData({
        page:this.data.page + 1
    })
    wx.showLoading({
      title: '加载中',
    })
    setTimeout(() => {
        this.getList()
        wx.hideLoading()
    }, 500);
  },

  toDetail(e){
    let id = e.currentTarget.dataset.id
    let back = this.data.list.filter(item => item.id == id)
    console.log(e);
    console.log(back);
    console.log(JSON.stringify(back));
    wx.navigateTo({
      url: `/pages/xqy/xqy?item=${JSON.stringify(back)}`,
    })
  },

  search(){
    wx.navigateTo({
      url: '../search/search',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})